<?php
define('CODE_MARK', 'code');

function imageCodeCreate(){
	$image = imagecreate(50,20);
	imagecolorallocate($image, 188, 188, 188);
	$color = imagecolorallocate($image, 27, 12, 209);
	$code = rand(1000, 2000);
	$_SESSION[CODE_MARK] = $code;
	imagefttext($image, 18, 0, 1, 19, $color, 'C:\Windows\Fonts\simhei.ttf', $code);
	$color = imagecolorallocate($image, 0,132,0);
	imageline($image, 0, 15, 70, 5, $color);
	imageline($image, 0, 3, 70, 23, $color);
	imageline($image, 0, 10, 80, 30, $color);
	
	return  $image;
}

function checkCode($rCode){
	if(empty($rCode)||empty($_SESSION[CODE_MARK])){
		return false;
	}
	$sCode = $_SESSION[CODE_MARK];
	unset($_SESSION[CODE_MARK]);
	return $rCode == $sCode;
}